package com.fr.base.dav;

import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLFileReader;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.TableData;
import com.fr.data.core.DataXMLUtils;
import com.fr.data.core.db.TableProcedure;
import com.fr.data.impl.Connection;
import com.fr.data.impl.DatabaseConnection;
import com.fr.report.io.xml.ReportXMLUtils;
import com.fr.report.parameter.Parameter;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

public class DavXMLUtils
{
  public static void writeXMLFileNodes(FileNode[] paramArrayOfFileNode, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new FileNodeArrayWriter(paramArrayOfFileNode));
  }

  public static FileNode[] readXMLFileNodes(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new FileNodeArrayReader(null));
    return ((localObject instanceof FileNode[]) ? (FileNode[])localObject : new FileNode[0]);
  }

  public static void writeXMLFileDatabaseConnection(DatabaseConnection paramDatabaseConnection, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new DatabaseConnectionWriter(paramDatabaseConnection));
  }

  public static DatabaseConnection readXMLDatabaseConnection(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new DatabaseConnectionReader(null));
    return ((localObject instanceof DatabaseConnection) ? (DatabaseConnection)localObject : null);
  }

  public static DatabaseConnection readXMLDatabaseMapConnection(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new DatabaseMapConnectionReader(null));
    return ((localObject instanceof DatabaseConnection) ? (DatabaseConnection)localObject : null);
  }

  public static void writeXMLFileTableData(TableData paramTableData, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new TableDataWriter(paramTableData));
  }

  public static TableData readXMLTableData(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new TableDataReader(null));
    return ((localObject instanceof TableData) ? (TableData)localObject : null);
  }

  public static void writeXMLFileParameters(Parameter[] paramArrayOfParameter, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new ParameterArrayWriter(paramArrayOfParameter));
  }

  public static Parameter[] readXMLParameters(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new ParameterArrayReader(null));
    return ((localObject instanceof Parameter[]) ? (Parameter[])localObject : new Parameter[0]);
  }

  public static void writeXMLFileSchema(String[] paramArrayOfString, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new SchemaWriter(paramArrayOfString));
  }

  public static String[] readXMLFileSchema(InputStream paramInputStream)
  {
    Object localObject = null;
    try
    {
      localObject = BaseXMLUtils.readXMLFile(paramInputStream, new SchemaReader(null));
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
    return ((localObject instanceof String[]) ? (String[])localObject : new String[1]);
  }

  public static void writeXMLFileSQLTable(TableProcedure[] paramArrayOfTableProcedure, OutputStream paramOutputStream)
  {
    BaseXMLUtils.writeXMLFile(paramOutputStream, new SQLTableArrayWriter(paramArrayOfTableProcedure));
  }

  public static TableProcedure[] readXMLSQLTables(InputStream paramInputStream)
    throws Exception
  {
    Object localObject = BaseXMLUtils.readXMLFile(paramInputStream, new SQLTableArrayReader(null));
    return ((localObject instanceof TableProcedure[]) ? (TableProcedure[])localObject : new TableProcedure[0]);
  }

  private static class SQLTableArrayReader
    implements XMLFileReader
  {
    private SQLTableArrayReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      ArrayList localArrayList = new ArrayList();
      if ("SQLTables".equals(str))
        paramXMLableReader.readXMLObject(new DavXMLUtils.3(this, localArrayList));
      return ((TableProcedure[])localArrayList.toArray(new TableProcedure[localArrayList.size()]));
    }

    public Object errorHandler()
    {
      return new TableProcedure[0];
    }

    SQLTableArrayReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class SQLTableArrayWriter
    implements XMLWriter
  {
    private TableProcedure[] sqlTables;

    SQLTableArrayWriter(TableProcedure[] paramArrayOfTableProcedure)
    {
      this.sqlTables = paramArrayOfTableProcedure;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      paramXMLPrintWriter.startTAG("SQLTables");
      int i = 0;
      int j = (this.sqlTables == null) ? 0 : this.sqlTables.length;
      while (i < j)
      {
        this.sqlTables[i].writeXML(paramXMLPrintWriter);
        ++i;
      }
      paramXMLPrintWriter.end();
    }
  }

  private static class SchemaReader
    implements XMLFileReader
  {
    private SchemaReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      ArrayList localArrayList = new ArrayList();
      if (str.equals("SchemaName"))
        paramXMLableReader.readXMLObject(new DavXMLUtils.2(this, localArrayList));
      String[] arrayOfString = new String[localArrayList.size()];
      for (int i = 0; i < localArrayList.size(); ++i)
        arrayOfString[i] = ((String)localArrayList.get(i));
      return arrayOfString;
    }

    public Object errorHandler()
    {
      return new String[0];
    }

    SchemaReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class SchemaWriter
    implements XMLWriter
  {
    private String[] schema;

    public SchemaWriter(String[] paramArrayOfString)
    {
      this.schema = paramArrayOfString;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      paramXMLPrintWriter.startTAG("SchemaName");
      for (int i = 0; i < ((this.schema == null) ? 0 : this.schema.length); ++i)
        paramXMLPrintWriter.startTAG("Schema").textNode(this.schema[i]).end();
      paramXMLPrintWriter.end();
    }
  }

  private static class ParameterArrayReader
    implements XMLFileReader
  {
    private ParameterArrayReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      if ("Parameters".equals(str))
        return ReportXMLUtils.readParameters(paramXMLableReader);
      return null;
    }

    public Object errorHandler()
    {
      return new Parameter[0];
    }

    ParameterArrayReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class ParameterArrayWriter
    implements XMLWriter
  {
    private Parameter[] parameters;

    ParameterArrayWriter(Parameter[] paramArrayOfParameter)
    {
      this.parameters = paramArrayOfParameter;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      ReportXMLUtils.writeParameters(paramXMLPrintWriter, this.parameters);
    }
  }

  private static class TableDataReader
    implements XMLFileReader
  {
    private TableDataReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      if ("TableData".equals(str))
        return DataXMLUtils.readXMLTableData(paramXMLableReader);
      return null;
    }

    public Object errorHandler()
    {
      return null;
    }

    TableDataReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class TableDataWriter
    implements XMLWriter
  {
    private TableData data;

    TableDataWriter(TableData paramTableData)
    {
      this.data = paramTableData;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      DataXMLUtils.writeXMLTableData(paramXMLPrintWriter, this.data);
    }
  }

  private static class DatabaseMapConnectionReader
    implements XMLFileReader
  {
    private DatabaseMapConnectionReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      if ("ConnectionMap".equals(str))
      {
        Connection localConnection = DataXMLUtils.readXMLConnectionMap(paramXMLableReader);
        if (localConnection instanceof DatabaseConnection)
          return localConnection;
      }
      return null;
    }

    public Object errorHandler()
    {
      return null;
    }

    DatabaseMapConnectionReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class DatabaseConnectionReader
    implements XMLFileReader
  {
    private DatabaseConnectionReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      if ("Connection".equals(str))
      {
        Connection localConnection = DataXMLUtils.readXMLConnection(paramXMLableReader);
        if (localConnection instanceof DatabaseConnection)
          return localConnection;
      }
      return null;
    }

    public Object errorHandler()
    {
      return null;
    }

    DatabaseConnectionReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class DatabaseConnectionWriter
    implements XMLWriter
  {
    private DatabaseConnection database;

    DatabaseConnectionWriter(DatabaseConnection paramDatabaseConnection)
    {
      this.database = paramDatabaseConnection;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      DataXMLUtils.writeXMLConnection(paramXMLPrintWriter, this.database);
    }
  }

  private static class FileNodeArrayReader
    implements XMLFileReader
  {
    private FileNodeArrayReader()
    {
    }

    public Object readFileContent(XMLableReader paramXMLableReader)
    {
      String str = paramXMLableReader.getTagName();
      ArrayList localArrayList = new ArrayList();
      if ("NODES".equals(str))
        paramXMLableReader.readXMLObject(new DavXMLUtils.1(this, localArrayList));
      return ((FileNode[])localArrayList.toArray(new FileNode[localArrayList.size()]));
    }

    public Object errorHandler()
    {
      return new FileNode[0];
    }

    FileNodeArrayReader(DavXMLUtils.1 param1)
    {
    }
  }

  private static class FileNodeArrayWriter
    implements XMLWriter
  {
    private FileNode[] fileNodes;

    FileNodeArrayWriter(FileNode[] paramArrayOfFileNode)
    {
      this.fileNodes = paramArrayOfFileNode;
    }

    public void writeXML(XMLPrintWriter paramXMLPrintWriter)
    {
      paramXMLPrintWriter.startTAG("NODES");
      int i = 0;
      int j = (this.fileNodes == null) ? 0 : this.fileNodes.length;
      while (i < j)
      {
        this.fileNodes[i].writeXML(paramXMLPrintWriter);
        ++i;
      }
      paramXMLPrintWriter.end();
    }
  }
}